<template>
    <div>
        <div v-title>我的</div>
        <div class="navtop">
            <img src="../image/background.png">
            <div class="topnews">
                <img src="../image/defaultImg.png" v-if="datalist.HeadPhoto==null||datalist.HeadPhoto==''">
                <img :src="GetImgPath(datalist.HeadPhoto,200,200)" v-else>
            </div>
            <div class="topnewsGoods">
                <div>{{datalist.NickName}}<br>{{datalist.Phone}}</div>
            </div>
        </div>
        <van-cell-group class="group">
            <van-cell title="保费报价" is-link class="cell" @click="Jump">
                <span style="color:#f33e16" v-show="num!=0">{{num}}条新报价</span>
            </van-cell>
            <van-cell title="客服热线" is-link @click="Call('400-170-1235')" class="cell">
                <span style="color:#999999">400-170-1235</span>
            </van-cell>
            <van-cell title="注册日期" class="cell">
                <span style="color:#999999">{{datalist.AddTime}}</span>
            </van-cell>

        </van-cell-group>
        <van-cell-group class="group">
            <van-cell title="我是代理商" is-link class="cell" v-show="datalist.IsCertification==3">
                <span style="color:#f33e16">待审核</span>
            </van-cell>
            <van-cell title="我是代理商" is-link class="cell" v-show="datalist.IsCertification==1" @click="IAmAgent">
                <span style="color:#2491ff">已认证</span>
            </van-cell>
            <van-cell title="我是代理商" is-link class="cell" v-show="datalist.IsCertification==0" @click="Authentication">
                <span style="color:#999999">去认证</span>
            </van-cell>
            <van-cell title="我是代理商" is-link class="cell" v-show="datalist.IsCertification==2" @click="Authentication">
                <span style="color:#f33e16">认证失败</span>
            </van-cell>
        </van-cell-group>
        <!--<van-cell-group class="group">
                                                                                <van-cell title="修改密码" is-link to="/ChangePwd" class="cell">
                                                                                </van-cell>
                                                                            </van-cell-group>-->
        <div class="SignOut" @click="SignOut">退出登录</div>
    </div>
</template>
<script>
import api from "../fetch/api.js";
import { Cell, CellGroup, Dialog, Toast } from "vant";
export default {
    components: {
        [Cell.name]: Cell,
        [CellGroup.name]: CellGroup,
        [Dialog.name]: Dialog,
        [Toast.name]: Toast
    },
    data() {
        return {
            datalist: "",
            num: ""
        };
    },
    mounted() {
        this.GetModel();
        this.NewCount();
    },
    methods: {
        Authentication() {
            this.$router.push("/Agent");
        },
        IAmAgent() {
            this.$router.push("/IAmAgent");
        },
        Jump() {
            this.$router.push("/OfferList");
        },
        GetModel() {
            api.GetModel().then(res => {
                this.datalist = res;
            });
        },
        NewCount() {
            api.NewCount().then(res => {
                this.num = res.Infor;
            });
        },
        SignOut() {
            Dialog.confirm({
                title: "提示",
                message: "是否退出？"
            })
                .then(() => {
                    api.LoginOut().then(res => {
                        if (res.Success == true) {
                            Toast({ message: res.Msg, position: "top" });
                            location.href = "http://m.nbbaijin.com/";
                        } else {
                            Toast({ message: res.Msg, position: "top" });
                        }
                    });
                })
                .catch(() => {
                    // on cancel
                });
        },
        GetImgPath(Url, Width, Height) {
            if (Url == null) {
                return;
            }
            if (Url == undefined) {
                return;
            }
            return Url;
            // if (Url.indexOf('jpg') < 0 && Url.indexOf('jpeg') < 0 && Url.indexOf('png') < 0) {
            //     Url = Url.substring(0, Url.length - 3) + '64';
            //     return Url;
            // }
            Url = Url.toLocaleLowerCase();
            var w = Width || 200;
            var h = Height || 200;
            if (w > 2000) w = 2000;
            if (h > 2000) h = 2000;
            var type = Url.substring(Url.lastIndexOf("."));
            return Url + "." + w + "x" + h + type;
        },
        Call(tel) {
            Dialog.confirm({
                title: "提示",
                message: "是否拨打" + tel
            })
                .then(() => {
                    window.location.href = "tel:" + tel;
                })
                .catch(() => {
                    // on cancel
                });
        }
    }
};
</script>
<style scoped>
.navtop {
    position: relative;
}

.navtop>img {
    width: 100%;
}

.topnews {
    position: absolute;
    left: 5%;
    top: 26%;
    width: 28%;
}

.topnews img {
    width: 70%;
    border-radius: 50px;
    border: 2px solid #9f9695;
    float: left;
}

.topnewsGoods {
    position: absolute;
    left: 30%;
    top: 30%;
    width: 50%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #fff;
}

.cell {
    width: 95%;
    margin-left: 5%;
}

.group {
    margin-top: 10px;
    background: #fff;
}

.SignOut {
    width: 90%;
    margin: 0px auto;
    text-align: center;
    height: 44px;
    line-height: 44px;
    background: #2491ff;
    font-size: 16px;
    color: #fff;
    border-radius: 5px;
    margin-top: 30px;
}

.topnews div {
    color: #fff;
    font-size: 18px;
    line-height: 35px;
}
</style>

